package com.teamone.etl.apimanager.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.teamone.etl.apimanager.entity.ApiType;
import com.teamone.etl.apimanager.request.BaseQuery;
import com.teamone.etl.apimanager.service.ApiTypeService;
import com.teamone.etl.apimanager.valid.AddGroup;
import com.teamone.etl.apimanager.valid.UpdateGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 接口类型表(ApiType)表控制层
 *
 * @author makejava
 * @since 2021-01-20 18:32:07
 */
@RestController
@RequestMapping("apiType")
public class ApiTypeController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private ApiTypeService apiTypeService;

    /**
     * 查询接口类型列表
     * @param baseQuery 分页对象
     * @return 返回列表
     */
    @PostMapping
    public R<PageInfo<ApiType>> selectAll(@RequestBody BaseQuery baseQuery){
        return success(apiTypeService.selectAll(baseQuery));
    }

    /**
     * 根据id删除接口类型（逻辑删除）
     * @param id 类型id
     * @return 删除结果
     */
    @DeleteMapping("{id}")
    public R logicDeleteById(@PathVariable Integer id){
        apiTypeService.logicDeleteById(id);
        return success(true);
    }

    /**
     * 修改单条接口类型
     * @param apiType 修改接口类型对象
     * @return 修改结果
     */
    @PutMapping
    public R updateOne(@RequestBody @Validated(UpdateGroup.class) ApiType apiType){
        apiTypeService.updateOne(apiType);
        return success(true);
    }

    /**
     * 新增接口类型
     * @param apiType 新增对象
     * @return 新增结果
     */
    @PostMapping("save")
    public R saveOne(@RequestBody @Validated(AddGroup.class) ApiType apiType){
        apiTypeService.saveOne(apiType);
        return success(true);
    }

}